package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.VideoRecoverStation;
import com.ruoyi.service.IVideoRecoverStationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 视频回收站Controller
 * 
 * @author ruoyi
 * @date 2025-09-12
 */
@RestController
@RequestMapping("/videoRecoverStation/videoRecoverStation")
public class VideoRecoverStationController extends BaseController
{
    @Autowired
    private IVideoRecoverStationService videoRecoverStationService;

    /**
     * 查询视频回收站列表
     */
    @PreAuthorize("@ss.hasPermi('videoRecoverStation:videoRecoverStation:list')")
    @GetMapping("/list")
    public TableDataInfo list(VideoRecoverStation videoRecoverStation)
    {
        startPage();
        List<VideoRecoverStation> list = videoRecoverStationService.selectVideoRecoverStationList(videoRecoverStation);
        return getDataTable(list);
    }

    /**
     * 导出视频回收站列表
     */
    @PreAuthorize("@ss.hasPermi('videoRecoverStation:videoRecoverStation:export')")
    @Log(title = "视频回收站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VideoRecoverStation videoRecoverStation)
    {
        List<VideoRecoverStation> list = videoRecoverStationService.selectVideoRecoverStationList(videoRecoverStation);
        ExcelUtil<VideoRecoverStation> util = new ExcelUtil<VideoRecoverStation>(VideoRecoverStation.class);
        util.exportExcel(response, list, "视频回收站数据");
    }

    /**
     * 获取视频回收站详细信息
     */
    @PreAuthorize("@ss.hasPermi('videoRecoverStation:videoRecoverStation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(videoRecoverStationService.selectVideoRecoverStationById(id));
    }

    /**
     * 新增视频回收站
     */
    @PreAuthorize("@ss.hasPermi('videoRecoverStation:videoRecoverStation:add')")
    @Log(title = "视频回收站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VideoRecoverStation videoRecoverStation)
    {
        return toAjax(videoRecoverStationService.insertVideoRecoverStation(videoRecoverStation));
    }

    /**
     * 修改视频回收站
     */
    @PreAuthorize("@ss.hasPermi('videoRecoverStation:videoRecoverStation:edit')")
    @Log(title = "视频回收站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoRecoverStation videoRecoverStation)
    {
        return toAjax(videoRecoverStationService.updateVideoRecoverStation(videoRecoverStation));
    }

    /**
     * 删除视频回收站
     */
    @PreAuthorize("@ss.hasPermi('videoRecoverStation:videoRecoverStation:remove')")
    @Log(title = "视频回收站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(videoRecoverStationService.deleteVideoRecoverStationByIds(ids));
    }

    /**
     * 恢复视频数据
     */
    @PreAuthorize("@ss.hasPermi('videoRecoverStation:videoRecoverStation:recover')")
    @Log(title = "视频回收站", businessType = BusinessType.OTHER)
    @PostMapping("/recoverData/{recoverIds}")
    public AjaxResult recoverData(@PathVariable Long[] recoverIds){
        if (recoverIds == null || recoverIds.length == 0) {
            return error("请选择要恢复的数据");
        }
        // 返回操作结果和恢复数量
        AjaxResult ajaxResult = AjaxResult.success();
        int count = videoRecoverStationService.recoverVideoData(recoverIds);
        ajaxResult.put("msg", "成功恢复 " + count + " 条数据");

        return ajaxResult;
    }
}
